package com.woniu113.junk.user.controller;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu113.junk.user.Param.PageParam;
import com.woniu113.junk.user.controller.form.PageForm;
import com.woniu113.junk.user.model.AdminRole;
import com.woniu113.junk.user.service.AdminRoleService;
import com.woniu113.junk.commons.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 蜡笔没了小新
 * @since 2024年10月17日
 */
@RestController
@RequestMapping("/adminRole")
@Api("管理员角色相关")
public class AdminRoleController {
    @Resource
    private AdminRoleService adminRoleService;
    @GetMapping("/addRole")
    @ApiOperation("添加角色")
    public Result addRole(@RequestParam String role){
        adminRoleService.addRole(role);
        return Result.getResult().setMsg("添加成功");
    }
    @PostMapping("/selectRole")
    @ApiOperation("查询角色")
    public Result<Page<AdminRole>> selectRole(@RequestBody PageForm form){
        Page<AdminRole> adminRolePageInfo = adminRoleService.selectRole(BeanUtil.toBean(form, PageParam.class));
        return Result.getPageResult(AdminRole.class).setData(adminRolePageInfo);
    }
    @GetMapping("/deleteRole")
    @ApiOperation("删除角色")
    public Result deleteRole(@RequestParam Integer id) {
        adminRoleService.deleteRole(id);
        return Result.getResult().setMsg("删除成功");
    }
    @PostMapping("/modifyRole")
    @ApiOperation("修改角色")
    public Result modifyRole(@RequestBody AdminRole adminRole) {
        adminRoleService.saveOrUpdate(adminRole);
        return Result.getResult().setMsg("修改成功");
    }
    @GetMapping("/selectRoleById")
    @ApiOperation("根据id查询角色")
    public Result<AdminRole> selectRoleById(@RequestParam Integer id) {
        AdminRole adminRole = adminRoleService.getById(id);
        return Result.getResult(AdminRole.class).setData(adminRole);
    }
}

